/**
 * https://leetcode-cn.com/problems/container-with-most-water/
 * 盛最多水的容器
 * @param height 
 */
const maxArea = (height: number[]): number => {
    const len = height.length;

    let s = 0,
        e = len - 1,
        // 初始的最大值
        max = 0;

    while (s < e) {
        const leftMin = (height[s] - height[e]) < 0
        let curr = (leftMin ? height[s] : height[e]) * (e - s)
        max = Math.max(curr, max)

        // 移动较小的指针
        if (leftMin) {
            s++
        } else {
            e--
        }
    }


    return max
};

// 暴力法
const maxArea2 = (height: number[]): number => {
    const len = height.length;
    let max = 0

    // 每一根柱子都比较
    for (let i = 0; i < len; i++) {
        for (let j = i + 1; j < len; j++) {
            max = Math.max(max, Math.min(height[i], height[j]) * (j - i))
        }
    }

    return max
};

console.log(maxArea([1, 8, 6, 2, 5, 4, 8, 3, 7]))